package com.example.travel.controller;

import com.example.travel.pojo.ResultType;
import com.example.travel.pojo.orm.User;
import com.example.travel.pojo.result.UploadResult;
import com.example.travel.service.FriendUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class FriendController {
    @Autowired
    private FriendUserService friendUserService;

    @GetMapping("/user/get_friends")
    public List<User> getFriends(@RequestParam("userId") Integer userId){
        return friendUserService.getFriendsByUserId(userId);
    }

    @GetMapping("/user/add_friend")
    public UploadResult addFriend(@RequestParam("userId")Integer userId,@RequestParam("friendId")Integer friendId){
        if (friendUserService.addFriendUser(userId, friendId)){
            return new UploadResult(ResultType.SUCCESS);
        }else {
            return new UploadResult(ResultType.FAIL);
        }


    }
}
